import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import departments from './modules/departments'
import employees from './modules/employees'
import settings from './modules/settings'
import permissions from './modules/permissions'
import salarys from './modules/salarys'
// 创建动态路由表
const asyncRoutes = [
  departments,
  employees,
  settings,
  permissions,
  salarys
]
// 静态路由表
export const constantRoutes = [
  // 登录
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  // 404
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 首页
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  // desp
  // // 社保管理
  // {
  //   path: '/social_securitys',
  //   component: Layout,
  //   children: [{
  //     path: '', // 子组件path为空,默认自动匹配
  //     name: 'social_securitys',
  //     component: () => import('@/views/social_securitys/social_securitys.vue'),
  //     meta: { title: '社保管理', icon: 'table' }
  //   }]
  // },
  // // 考勤管理
  // {
  //   path: '/attendance',
  //   component: Layout,
  //   children: [{
  //     path: '', // 子组件path为空,默认自动匹配
  //     name: 'attendance',
  //     component: () => import('@/views/attendance/attendance.vue'),
  //     meta: { title: '考勤管理', icon: 'skill' }
  //   }]
  // },
  // // 审批管理
  // {
  //   path: '/approvals',
  //   component: Layout,
  //   children: [{
  //     path: '', // 子组件path为空,默认自动匹配
  //     name: 'approvals',
  //     component: () => import('@/views/approvals/approvals.vue'),
  //     meta: { title: '审批管理', icon: 'tree-table' }
  //   }]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...asyncRoutes] // 最终生成的路由(将静态路由表和动态路由表合并到一起)
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
